<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%@ include file="../function.jsp"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>科室新闻管理</title>
    <link  href="../../images/favicon.ico?cache=<%=Math.random()%>" rel="shortcut icon" type="image/x-icon">
    <link rel="stylesheet" href="../../css/public.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="../../css/messages_doctor_mes.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="../../css/sweetalert.css?cache=<%=Math.random()%>" >
    <link rel="stylesheet" href="../../css/pageCode.css?cache=<%=Math.random()%>" />
    <script src="../../js/jquery-1.9.1.min.js"></script>
</head>
<body>
    <%@ include file="../../header.jsp"%>
    <!--内容-->
    <div class="containerone">
    <%@ include file="../../left_menu.jsp"%>
    <!--右边内容-->
    <div class="right_cont">
<!--右边导航下面内容-->
<div class="message_right_cont_box" id="news">
          <div class="message_right_cont_container">
              <!--左边的渠道-->
              <div class="department_top">
                        <div class="top_middle" v-html="deptName"></div>
               <div class="department_top_left">
                    <span>
                     <p class="padding-right-min">新闻分类:</p>
                    <select class="news_option_sel" id="news_option_sel" @change="choose_news()" >
                    <template v-for="label in labels">
                    <option  :value="label.id"  v-html="label.name"></option>
                    </template>
                    </select>
                     </span>
                  </div>
                  <!--右边的搜索\添加\批量添加-->
                  <div class="department_top_right">
                   <span class="add_btn doctor_add_btn" @click="back()">返回</span>
                    <%
                                                if (checkAuth("添加科室新闻", input)) {
                                            %>
                   <a href="javascript:void(0);"><span class="add_btn doctor_add_btn" id='doctor_add_btn' @click="add_news()">添加</span></a>
                   <%
                                                }
                                            %>
                  </div>
                  <div class="clearfix"></div>
              </div>
<!--标题/发表日期/作者/操作-->
              <div class="department_detail" id="doctor_detail">
                  <table class="department_detail_table">
                    <tr class='department_detail_tittle'>
                    <td class='ui_widthone'>标题</td>
                    <td class='ui_widthone'>发表日期</td>
                    <td class='ui_widthone'>新闻作者</td>
                    <td class='ui_widthtwo'>操作</td>
                    </tr>
                      <%--<td>没有相关新闻列表</td>--%>
                  <template v-for="new in news.rank">
                      <tr class="department_detail_c">
                          <td v-html="limitnumber(new.title)"></td>
                          <td v-html="new.time"></td>
                          <td v-html="limitnumber(new.author)"></td>
                          <td class='ui_color'>
                        <%
                                                 if (checkAuth("查看科室新闻详情", input)) {
                                            %>
                             <span class="mes_doc_edit doctor_add_btn " @click="see_news(new.id)"><a>查看</a></span>
                         <%
                                                }
                                            %>
                          <%
                                                 if (checkAuth("编辑科室新闻", input)) {
                                            %>
                             <span class="mes_doc_edit doctor_add_btn"><a href="javascript:void(0);" @click="edit_news(new.id)">编辑</a></span>
                          <%
                                                }
                                            %>
                     <%
                                                 if (checkAuth("删除科室新闻", input)) {
                                            %>
                             <span class="delete_doc_mes" @click="delete_news(new.id)">删除</span>
                     <%
                                                }
                                            %>
                         </td>
                      </tr>
              </template>
                  </table>
              </div>
                <div class="split_pages">
                <div class="record">共<span class="ui_red"  v-html='news.count'></span>记录</div>
                <div class="tcdPageCode holder"></div>
                <input type="hidden" name="pageCount" value="">
                <input type="hidden" name="current_page" value="">
                </div>

          </div>
    </div>
    </div>
    </div>
<%--点击搜索和选择科室替换--%>

    <script src="../../js/sweetalert-dev.js"></script>
    <script src="../../js/jquery.page.js"></script>
<script>
    new Vue({
    el:'#news',
    data:{
    deptName:"",
    deptCode:"",
    option:"",
    option_id:"",
    labels:[],
    news:[],
    },
    ready: function() {
    var self = this;
    var news = getHrefParms("news");
    self.deptName = news.deptName;
    self.deptCode = news.deptCode;
    $.ajax({
    type: 'POST',
    url: "news.jsp",
    data: {
    act: "labels",
    category:3
    },
    success: function(res) {
    res = JSON.parse(res);
    if (res.errcode == 0) {
    self.labels = res.labels;
    self.option=self.labels[0].name;
    self.option_id=self.labels[0].id;
    $.ajax({
    type: 'POST',
    url: "news.jsp",
    data: {
    act:"news_list",
    labelId:self.labels[0].id,
    deptCode:self.deptCode,
    },
    success: function(res) {
    res = JSON.parse(res);

    if (res.errcode == 0) {
    self.news = res.data;
    $(".tcdPageCode").createPage({
    pageCount: self.news.page_count,
    current:self.news.current_page,
    backFn:function(p){
    $.ajax({
    type: 'post',
    url: "news.jsp",
    data: {
    act:"news_list",
    labelId:self.option_id,
    deptCode:self.deptCode,
    page:p
    },
    timeout: 3000,
    dataType: 'json',
    success: function(res) {
    if (res.errcode == 0) {
    self.news = res.data;
    }
    },
    error: function(error) {

    }
    });
    return false;//阻止提交
    }
    });
    }

    }
    })};

    }
    });
    },
    methods:{
    choose_news:function(){
    var self = this;
    var option=$('.news_option_sel option:selected').val();
    self.option=$('.news_option_sel option:selected').text();
    self.option_id=option;
    $.ajax({
    type: 'POST',
    url: "news.jsp",
    data: {
    act:"news_list",
    labelId:option,
    deptCode:self.deptCode,
    },
    success: function(res) {
    res = JSON.parse(res);
    if (res.errcode == 0) {
    self.news = res.data;
    $(".tcdPageCode").createPage({
    pageCount: self.news.page_count,
    current:self.news.current_page,
    <%--点击打印页数--%>
    backFn:function(p){
    $.ajax({
    type: 'post',
    url: "news.jsp",
    data: {
    act:"news_list",
    labelId:self.option_id,
    deptCode:self.deptCode,
    page:p
    },
    timeout: 3000,
    dataType: 'json',
    success: function(res) {
    if (res.errcode == 0) {
    self.news = res.data;
    }

    },
    error: function(error) {
    }
    });
    return false;//阻止提交
    }
    });
    }else{
    self.news = [];
    $(".tcdPageCode").createPage({
    pageCount: 0,
    current:0,
    });
    }
    }
    });
    },
    delete_news:function(id){
        swal({
        title: "您确定要删除吗？",
        type: "warning",
        showCancelButton: true,
        closeOnConfirm: false,
        confirmButtonText: "是的，我要删除",
        cancelButtonText:"取消",
        confirmButtonColor: "#ec6c62"
        },
        function(){
        $.ajax({
        type: 'post',
        url: "news.jsp",
        data: {
        act:"delete_news",
        news_id:id,
        },
        timeout: 3000,
        dataType: 'json',
        success:function (data) {
        if(data.errcode==0){
        self.location.reload()
        swal('删除成功')

        }else{
        swal('删除失败')
        }
        //console.log(data)
        },
        error:function (error) {
        swal('删除失败')
        }
        });
        return false;//阻止提交
        }
        );
    },
    limitnumber:function(txt) {
    if(txt.length>10){
    txt = txt.substr(0,8) + '......' ;
    return txt;
    }
    else{
    return txt;
    }

    },
    back:function(){
    locationHerf("see")
    },
    add_news:function(){
    var self=this;
    var deptCode=self.deptCode;
    var deptName=self.deptName;
    var option=self.option;
    var labelId=self.option_id;
    locationHerf("add_news",{
    deptCode:deptCode,
    deptName:deptName,
    option:option,
    labelId:labelId
    })
    },
    see_news:function(news_id){
    var self=this;
    var option=self.option;
    var deptCode=self.deptCode;
    var deptName=self.deptName;
    locationHerf("see_news",{
        news_id:news_id,
        option:option,
       deptName:deptName,
       deptCode:deptCode
      })
    },
    edit_news:function(news_id){
    var self=this;
    var option=self.option;
     locationHerf("edit_news",{
       news_id:news_id,
       option:option,
     })
    }
    }

    })
</script>
</body>
</html>
